package cn.com.controller;

import cn.com.beans.ProfessionInfo;
import cn.com.beans.ProfessionType;
import cn.com.service.ProfessionInfoService;
import cn.com.service.ProfessionSalaryService;
import cn.com.service.ProfessionTypeService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/profession")
public class ProfessionController {

    @Resource
    private ProfessionInfoService professionInfoService;
    @Resource
    private ProfessionTypeService professionTypeService;
    @Resource
    private ProfessionSalaryService professionSalaryService;

    @GetMapping
    public String profession(Model model) {
        List<ProfessionInfo> professionInfoList = professionInfoService.findAll(null);
        List<ProfessionType> professionTypeList = professionTypeService.findAll(null);
        model.addAttribute("infoList", professionInfoList);
        model.addAttribute("typeList", professionTypeList);
        return "query/professionList";
    }
    @GetMapping("/find")
    public String find(Integer id,Model model) {
        ProfessionInfo professionInfo = professionInfoService.selectByPrimaryKey(id);
        Integer ptId = professionInfo.getPrPtid();
        ProfessionType professionType = professionTypeService.selectByPrimaryKey(ptId);
        String name = professionType.getPtName();
        for(int i = 1;i <= 11;i++) {
            int money = professionSalaryService.findMoneyByPridAndYear(id, i);
            System.out.println("第"+i+"年"+money);
            model.addAttribute("money"+i, money);
        }
        model.addAttribute("name", name);
        model.addAttribute("profession", professionInfo);
        return "query/professionInfo";
    }

}
